Major coal-using countries including Poland, Vietnam and Chile are among those to make the commitment.
But some of the world’s biggest coal-dependent countries, including China and the US, did not sign up.
In a separate commitment, 20 countries, including the US, pledged to end public financing for “unabated” fossil fuel projects abroad by the end of 2022.
Such projects burn fossil fuels, like coal, oil and natural gas, without using technology to capture the CO2 emissions.
Coal is the single biggest contributor to climate change.
What is the coal pledge?
Signatories to the agreement have committed to ending all investment in new coal power generation domestically and internationally.
They have also agreed to phase out coal power in the 2030s for major economies, and the 2040s for poorer nations, the UK said.
Dozens of organisations also signed up to the pledge, with several major banks agreeing to stop financing the coal industry.
“The end of coal is in sight,” UK business and energy secretary Kwasi Kwarteng said.
“The world is moving in the right direction, standing ready to seal coal’s fate and embrace the environmental and economic benefits of building a future that is powered by clean energy.”
But UK shadow business secretary Ed Miliband said there were “glaring gaps” from China and other large emitters, who have not committed to stop increasing coal use domestically. He also noted that there was nothing on the phasing out of oil and gas.
Mr Miliband said the UK government “has let others off the hook”.
Although progress has been made in reducing coal use globally, it still produced around 37% of the world’s electricity in 2019.
Countries like South Africa, Poland and India will need major investments to make their energy sectors cleaner.
Juan Pablo Osornio, head of Greenpeace’s delegation at COP26, said: “Overall this statement still falls well short of the ambition needed on fossil fuels in this critical decade.”
“The small print seemingly gives countries enormous leeway to pick their own phase-out date, despite the shiny headline,” he added.
There’s been such a flurry of announcements on the world’s most polluting fossil fuel, that it’s hard to see the light for all the (coal) dust.
There are many questions outstanding.
One of the biggest is the list of countries missing from this bonfire of coal commitments – including the US, China and India.
The time scales for phase-out are also a bit woolly – with richer countries promising to end coal by the 2030s, with developing nations in the 2040s.
None of these commitments are binding – again there is no big stick to force countries to do this.
And how many of the plans to stop using coal in developing countries will need financial support from the developed world?
We’ve already seen the UK, Germany and the US step up to pay South Africa’s $8.5bn (£6.2bn) to move away from coal. Other countries are said to be interested in following in South Africa’s footsteps.
So is there also a question of the rich countries paying others to do what they struggle to do at home?
While the US was notably absent from the coal commitments, it joined 19 other countries – including the UK, Canada and New Zealand – in pledging to stop financing unabated overseas fossil fuel projects.
“Investing in unabated fossil-related energy projects increasingly entails both social and economic risks… and has ensuing negative impacts on government revenue, local employment, taxpayers, utility ratepayers and public health,” the signatories of the UK-led initiative said in a joint statement.
The deal saw countries and financial institutions vow to steer their spending into clean energy instead.
It allowed for exemptions in unspecified “limited” circumstances, but said these must be consistent with efforts to limit global temperature rises to 1.5C.
“Ending international finance for all unabated fossil fuels is the next critical frontier we must deliver on,” UK energy minister Greg Hands said. “We must put public finance on the right side of history.”
However, major financers of such projects, such as China, Japan and South Korea, did not sign up.
The countries did join G20 nations last month in agreeing to end financial support for new unabated coal plants overseas.